package com.chance.cc.crawler.development.bootstrap.weibo.subscribe;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

import java.util.HashMap;
import java.util.Map;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRecordFilter.key;
import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/**
 * @Author Zhao.Hhuan
 * @Date Create in 2021/1/28 16:50
 * @Description
 *      微博api订阅
 **/
public class WeiboApiSubscribe {
    private static final String domain = "weibo";

    private static final String access_token = "2.00o4_w1HrAaeYBedf38e38b8SnITmD";
    private static final String source = "1428199813";


    public static void main(String[] args) {
        subscribeUpdateSubscribeRecord();
    }

    private static void subscribeUpdateSubscribeRecord(){
        String url = "https://c.api.weibo.com/subscribe/update_subscribe.json";
        String site = "updateSubscribe";
        String subid = "12333";
        CrawlerRequestRecord crawlerRequestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(domain))
                .filter(key)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domain))
                .needParsed(false)
                .releaseTime(System.currentTimeMillis())
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .build();
        crawlerRequestRecord.setDownload(false);
        crawlerRequestRecord.setSkipPipeline(true);
        crawlerRequestRecord.tagsCreator().bizTags().addDomain(domain);
        crawlerRequestRecord.tagsCreator().bizTags().addSite(site);
        Map<String,Object> extras = new HashMap<>();
        extras.put("source",source);
        extras.put("subid",subid);
        extras.put("type","add_uids");
        crawlerRequestRecord.getHttpRequest().setExtras(extras);

        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest("weibo_subscribe_userid_add_keyword",turnPageItem)
                .httpUrl("http://192.168.1.215:9599/v1/meta/"+domain+"/keys?site=userId")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();

        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()//控制台输出
//                .fileResultPipeline("D:\\chance\\log\\tets.log",true) //文件输出
                .requestRecord(crawlerRequestRecord)
                .supportRecord(keywordRecord)
                .build()
                .start();
    }

}
